
/***********************************************
If you include this file please add to your sma:
	stock d_custom_item_buy(id, item){
		//this is called when player buys item
	}
	
	add TITLE_DEALERS_MENU to yours language file. This will be title of dealers menu
	add ITEMS_MENU to yours language file. This will be title of items menu
*/

#if defined _dealers_stock_included
	#endinput
#endif

#define _dealers_stock_included

//{ Giving real items to player
stock d_give_item_from_dealer(id, item, dealer, bool:auto=false) {
	if(gDealersItems[dealer][item][Dii_Count] >0){
		new cost = gDealersItems[dealer][item][Dii_Cost];
		if(auto){
			new type = get_pcvar_num(gCvarAutoBuyCostType);
			switch(type){
				case 1: cost+= get_pcvar_num(gCvarAutoBuyCostVal);
				case 2: cost+= cost*get_pcvar_float(gCvarAutoBuyCostVal);
			}
		}
		new money = cs_get_user_money(id);
		if(money >= cost){
			gDealersItems[dealer][item][Dii_Count] --;
			money-=cost;
			cs_set_user_money(id, money);
			d_custom_item_buy(id, item);
			client_print(id, print_chat, "%s %L: %L [%L:%d]", PREFIX, id,"ITEM_BOUGHT", id, ITEM_NAMES[item], id, "COST", cost);
			return true;
		} else {
			if(!auto)
				client_print(id, print_chat, "%s %L", PREFIX, id, "NOT_ENOUGH_MONEY");
		}
	} else {
		if(!auto)
			client_print(id, print_chat, "%s %s %L (%L)", PREFIX, gDealerDef[dealer][Di_Name], id,"ITEMS_SOLD", id, ITEM_NAMES[item]);
	}
	return false;
}


stock d_get_dealers_items_count(dealer){
	new count =0 ;
	for(new item=0;item<ITEMS;item++)
		count += gDealersItems[dealer][item][Dii_Count];
	return count;
}


stock bool:d_anyDealerHaveItem(id, item){
	for(new dealer=0;dealer<MAX_DEALERS;dealer++){
		if(!gDealerDef[dealer][Di_Registered])
			continue;
		if(playerAvailableDealers[id][dealer] && gDealersItems[dealer][item][Dii_Count] >0)
			return true;
	}
	return false;
}
//}
